//
//  Home2TableViewCell.m
//  MobileOffice
//
//  Created by Appel on 16/10/17.
//  Copyright © 2016年 liaoningjujin. All rights reserved.
//

#import "Home2TableViewCell.h"

@implementation Home2TableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier isNeedGoOut:(BOOL)isNeedGoOut{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor=[UIColor clearColor];
        self.contentView.backgroundColor=[UIColor clearColor];
        //现在
        _nowLabel=[MyControl creatLabelWithFrame:CGRectMake(15, (isNeedGoOut?8+58:8), 40, 20) text:@"现在"];
        _nowLabel.font=FONT_14;
        _nowLabel.textAlignment=NSTextAlignmentCenter;

        [self.contentView addSubview:_nowLabel];
        //时间
        _timeLabel=[MyControl creatLabelWithFrame:CGRectMake(15, _nowLabel.y+_nowLabel.height, 40, 20) text:@""];
        _timeLabel.font=FONT_13;
        _timeLabel.textAlignment=NSTextAlignmentCenter;
        [self.contentView addSubview:_timeLabel];
        
        //时间轴
        _lineImageView=[MyControl creatImageViewWithFrame:CGRectMake(_timeLabel.x+_timeLabel.width+8, 0, 0.5,(isNeedGoOut?126+58:126)) imageName:@""];
        _lineImageView.backgroundColor=[UIColor lightGrayColor];
        [self.contentView addSubview:_lineImageView];
        
        UIView *goOutView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, 58)];
        [self.contentView addSubview:goOutView];
        if (isNeedGoOut) {
            
            _stateImageView2=[MyControl creatImageViewWithFrame:CGRectMake(_timeLabel.x+_timeLabel.width, 10, 16, 16) imageName:@"k_dian_2@2x"];
            [self.contentView addSubview:_stateImageView2];
            
            //公出记录
            _goOutButton=[MyControl creatButtonWithFrame:CGRectMake(_lineImageView.x+_lineImageView.width+15, 8, IPHONE_WIDTH-(_lineImageView.x+_lineImageView.width+15)-8, 50) target:self sel:@selector(goOutButtonClick) tag:100 image:nil title:@"公出记录"];
            _goOutButton.backgroundColor=[UIColor whiteColor];
            _goOutButton.layer.cornerRadius=5;
            _goOutButton.layer.borderColor=[[UIColor lightGrayColor]CGColor];
            _goOutButton.layer.borderWidth=0.5f;
            [_goOutButton setImage:[UIImage imageNamed:@"k_ic_1paizhao@2x"] forState:UIControlStateNormal];
            //调整文字和图片的位置
            [_goOutButton setTitleEdgeInsets:UIEdgeInsetsMake(0,-_goOutButton.imageView.width, 0, _goOutButton.imageView.width)];
            [_goOutButton setImageEdgeInsets:UIEdgeInsetsMake(0, _goOutButton.titleLabel.width+10, 0, -_goOutButton.titleLabel.width)];
            [goOutView addSubview:_goOutButton];
        }else{
            goOutView.height=0;
        }
        

        
        _stateImageView=[MyControl creatImageViewWithFrame:CGRectMake(_timeLabel.x+_timeLabel.width, (isNeedGoOut?10+58:10), 16, 21) imageName:@"checkbox_normal@2x"];
        [self.contentView addSubview:_stateImageView];
        
        //办公区域
        _backView=[[UIView alloc]initWithFrame:CGRectMake(_lineImageView.x+_lineImageView.width+15, 8+goOutView.y+goOutView.height, IPHONE_WIDTH-(_lineImageView.x+_lineImageView.width+15)-8, 100)];
        _backView.backgroundColor=[UIColor whiteColor];
        _backView.layer.cornerRadius=5;
        [self.contentView addSubview:_backView];
        
        //待处理工作
        _titleLabel1=[MyControl creatLabelWithFrame:CGRectMake(5, 8, _backView.width/2, 20) text:@"待我处理工作"];
        _titleLabel1.font=FONT_14;
        [_backView addSubview:_titleLabel1];
        
        //待处理任务数量
        _workNumber1=[MyControl creatLabelWithFrame:CGRectMake(5, _titleLabel1.y+_titleLabel1.height, _titleLabel1.width-20, 20) text:@""];
        _workNumber1.font=[UIFont systemFontOfSize:18 weight:1];
        _workNumber1.textColor=COLOR_SKYBLUE;
        //字体位置
        _workNumber1.textAlignment=NSTextAlignmentCenter;
        [_backView addSubview:_workNumber1];
        
        UILabel *label1=[MyControl creatLabelWithFrame:CGRectMake(_workNumber1.x+_workNumber1.width-8, _workNumber1.y, 20, 20) text:@"项"];
        label1.font=FONT_14;
        [_backView addSubview:label1];
        
        //将超时工作数分拆为三段
        UILabel *label2=[MyControl creatLabelWithFrame:CGRectMake(_titleLabel1.x, _workNumber1.y+_workNumber1.height, _titleLabel1.width-47, 20) text:@"其中超时:"];
        label2.font=FONT_11;
        label2.textAlignment=NSTextAlignmentRight;
        label2.textColor=[UIColor lightGrayColor];
        [_backView addSubview:label2];
        
        _overTimeNumber1=[MyControl creatLabelWithFrame:CGRectMake(label2.x+label2.width, label2.y, 25, 20) text:@""];
        _overTimeNumber1.font=[UIFont systemFontOfSize:15 weight:1];
        _overTimeNumber1.textColor=[UIColor redColor];
        _overTimeNumber1.font=FONT_12;
        _overTimeNumber1.textAlignment=NSTextAlignmentCenter;
        [_backView addSubview:_overTimeNumber1];
        
        
        UILabel *label3=[MyControl creatLabelWithFrame:CGRectMake(_titleLabel1.width-20-8, label2.y, 20, 20) text:@"项"];
        label3.font=FONT_11;
        label3.textAlignment=NSTextAlignmentRight;
        label3.textColor=[UIColor lightGrayColor];
        [_backView addSubview:label3];
        
        //分割线
        UILabel* _line=[[UILabel alloc]initWithFrame:CGRectMake(_backView.width/2, 5, 1, _backView.height-40)];
        _line.backgroundColor=BACKCOLOR_GRAY;
        [_backView addSubview:_line];
        
        //我发起的工作
        _titleLabel2=[MyControl creatLabelWithFrame:CGRectMake(_backView.width/2+5, 8, _backView.width/2, 20) text:@"我发起的工作"];
        _titleLabel2.font=FONT_14;
        [_backView addSubview:_titleLabel2];
        
        //我发起的任务数量
        _workNumber2=[MyControl creatLabelWithFrame:CGRectMake(_titleLabel2.x, _titleLabel2.y+_titleLabel2.height, _titleLabel2.width-20, 20) text:@""];
        _workNumber2.font=[UIFont systemFontOfSize:18 weight:1];
        _workNumber2.textColor=COLOR_SKYBLUE;
        //字体位置
        _workNumber2.textAlignment=NSTextAlignmentCenter;
        [_backView addSubview:_workNumber2];
        
        UILabel *myWorkLabel1=[MyControl creatLabelWithFrame:CGRectMake(_workNumber2.x+_workNumber2.width-8, _workNumber2.y, 20, 20) text:@"项"];
        myWorkLabel1.font=FONT_14;
        [_backView addSubview:myWorkLabel1];
        
        //将超时工作数分拆为三段
        UILabel *myWorkLabel2=[MyControl creatLabelWithFrame:CGRectMake(_titleLabel2.x, _workNumber2.y+_workNumber2.height, _titleLabel2.width-47, 20) text:@"其中超时:"];
        myWorkLabel2.font=FONT_11;
        myWorkLabel2.textAlignment=NSTextAlignmentRight;
        myWorkLabel2.textColor=[UIColor lightGrayColor];
        [_backView addSubview:myWorkLabel2];
        
        _overTimeNumber2=[MyControl creatLabelWithFrame:CGRectMake(myWorkLabel2.x+myWorkLabel2.width, myWorkLabel2.y, 25, 20) text:@""];
        _overTimeNumber2.font=[UIFont systemFontOfSize:15 weight:1];
        _overTimeNumber2.textColor=[UIColor redColor];
        _overTimeNumber2.font=FONT_12;
        _overTimeNumber2.textAlignment=NSTextAlignmentCenter;
        [_backView addSubview:_overTimeNumber2];
        
        
        UILabel *myWorkLabel3=[MyControl creatLabelWithFrame:CGRectMake(_backView.width-20-8, myWorkLabel2.y, 20, 20) text:@"项"];
        myWorkLabel3.font=FONT_11;
        myWorkLabel3.textAlignment=NSTextAlignmentRight;
        myWorkLabel3.textColor=[UIColor lightGrayColor];
        [_backView addSubview:myWorkLabel3];
        //待我处理工作
        _workButton1=[MyControl creatButtonWithFrame:CGRectMake(0, 0, _backView.width/2, 60) target:self sel:@selector(dutyClick) tag:201 image:nil title:@""];
        _workButton1.backgroundColor=[UIColor clearColor];
//        _workButton1.titleLabel.font=FONT_16;
//        [_workButton1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_backView addSubview:_workButton1];
        
        //职责按钮
        _workButton2=[MyControl creatButtonWithFrame:CGRectMake(_backView.width/2, 0, _backView.width/2, 60) target:self sel:@selector(dutyClick) tag:202 image:nil title:@""];
//        _workButton2.backgroundColor=[UIColor clearColor];
//        _workButton2.titleLabel.font=FONT_16;
        [_workButton2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_backView addSubview:_workButton2];
        
        //职责按钮
        _dutyButton=[MyControl creatButtonWithFrame:CGRectMake(0, _backView.height-30, _backView.width, 40) target:self sel:@selector(dutyClick) tag:200 image:nil title:@"职责"];
        _dutyButton.backgroundColor=COLOR_MIDBLUE;
        _dutyButton.titleLabel.font=FONT_16;
        [_dutyButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_backView addSubview:_dutyButton];
    }
    return self;
}


- (void)setCellInfoWithModel:(SignInInfoModel *)model{
    //取得数据
    NSArray *infoArr=[LZXHelper getArrWithStr:model.eventName componentsStr:@"|"];
    if (infoArr.count>0) {
        _workNumber1.text=infoArr[0];
        _overTimeNumber1.text=infoArr.count>1?infoArr[1]:@"";
        _workNumber2.text=infoArr.count>2?infoArr[2]:@"";
        _overTimeNumber2.text=infoArr.count>3?infoArr[3]:@"";
    }
    _timeLabel.text=[LZXHelper getTimeStrWithOldDateFomatter:@"yyyy-MM-dd HH:mm:ss" DateStr:model.eventTime newFormatter:@"HH:mm"];
    [_stateImageView setImage:[UIImage imageNamed:@"k_current@2x"]];

}

- (void)dutyClick{
    
}

#pragma mark -公出记录
- (void)goOutButtonClick{
    if (self.myBlock) {
        self.myBlock();
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
